/*================================================
 * 
 * Createtime : 2016/05/26
 * Author : luo yanming
 * 
 ================================================*/
define(function(require, exports, module) {
	var $ = require('jquery'),
        util = require('util');

    var index = {
        init: function(){
        	index.bind();
        },
        bind: function(){

            index.bannerSlideBind();
            index.impressionSlideBind();
            index.loanDriveModalBind();
        },
        bannerSlideBind: function(){
            var bannerSlideImgLi = $('.slide-box .slide-wrapper ul li'),
                bannerSlidePagiLi = $('.slide-box .slide-pagination ul li');

            bannerSlidePagiLi.on('click', function(e) {
                var _this = $(this);
                if(_this.hasClass('active')) {
                    return false;
                } else {
                    _this.addClass('active').siblings().removeClass('active');
                    bannerSlideImgLi.eq(_this.index()).addClass('active').siblings().removeClass('active');
                }
            });
        },
        impressionSlideBind: function(){
            var impressionSlideImgLi = $('.impression .list ul li'),
                impressionSlidePagiLi = $('.impression .pagi ul li');

            impressionSlidePagiLi.on('click', function(e) {
                var _this = $(this);
                if(_this.hasClass('active')) {
                    return false;
                } else {
                    _this.addClass('active').siblings().removeClass('active');
                    impressionSlideImgLi.eq(_this.index()).addClass('active').siblings().removeClass('active');
                }
            });
        },
        loanDriveModalBind: function() {
            var loan = $('.module-entrance .loan'),
                drive = $('.module-entrance .drive'),
                loanDriveModal = $('.loan-drive-modal');

            //购车贷款
            loan.on('click', function(){
                loanDriveModal.fadeIn();
                index.loanDriveModalShow(0);
            });

            //购车试驾
            drive.on('click', function(){
                loanDriveModal.fadeIn();
                index.loanDriveModalShow(1);
            });

            //关闭弹框
            loanDriveModal.on('click', function(e){
                if(e.target.nodeName == 'SECTION'){
                    loanDriveModal.fadeOut();
                }else{
                    return false;
                }
            });
        },
        loanDriveModalShow: function(type){
            var loanDriveModalNavLi = $('.loan-drive-modal .tab-nav ul li'),
                loanDriveModalListLi = $('.loan-drive-modal .tab-list ul li');

            loanDriveModalNavLi.eq(type).addClass('active').siblings().removeClass('active');
            loanDriveModalListLi.eq(type).addClass('active').siblings().removeClass('active');
        }
    }

    index.init();
});